package org.etherframework.tests.features.wiring.processors
{
	import org.etherframework.IEther;
	import org.etherframework.common.wire.IMetaProcessor;
	import org.etherframework.core.reflection.Accessor;
	import org.etherframework.core.reflection.MetadataMember;
	import org.etherframework.core.reflection.Method;
	import org.etherframework.core.reflection.Variable;
	
	public class HelloWorld implements IMetaProcessor
	{
		public static const NAME:String = "Hello";
		
		private var _destroyed:Boolean;
		private var _members:Vector.<MetadataMember>;
		
		public function wire(target:Object, members:Vector.<MetadataMember>, ether:IEther):void
		{
			_members = members;
			
			for each (var member:MetadataMember in members)
			{
				if ((member is Accessor && Accessor(member).access == "readwrite") || 
					member is Variable)
				{
					target[member.qualifiedName] = "Hello World!";
				}
				else if (member is Method)
				{
					target[member.qualifiedName].apply(null, ["Hello World!"]);
				}
			}
		}
		
		public function unwire(target:Object):void
		{
			for each (var member:MetadataMember in _members)
			{
				if ((member is Accessor && Accessor(member).access == "readwrite") || 
					member is Variable)
				{
					target[member.qualifiedName] = null;
				}
				else if (member is Method)
				{
					target[member.qualifiedName].apply(null, [null]);
				}
			}
		}
		
		public function destroy():void
		{
		}
		
		public function get destroyed():Boolean { return _destroyed; }
		public function set destroyed(value:Boolean):void { _destroyed = value; }
	}
}